home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / xprz351s.lha / xprgetsystime.c < prev    next >
C/C++ Source or Header  |  1994-11-17  |  3KB  |  90 lines

  1. /**********************************************************************
  2.  * Amiga-type replacement for standard Unix time() function.  Can't use
  3.  * Lattice's time() function from within a library because it's not
  4.  * reentrant (has some hidden static vars it sets) and because it wants
  5.  * you to have opened dos.library for some reason, which is supposedly
  6.  * a bad idea inside a library.  Oh, well... this is quite a bit
  7.  * smaller & faster anyway.  B-)
  8.  **********************************************************************/
  9.  
  10. #include "xprzmodem_all.h"
  11.  
  12. /*
  13.  * # seconds between 1-1-70 (Unix time base) and 1-1-78 (Amiga time base).
  14.  * Add this value to the returned seconds count to convert Amiga system time
  15.  * to normal Unix system time.
  16.  */
  17.  
  18. ULONG UnixTimeOffset = 252482400;
  19.  
  20. #ifdef zedzap
  21. /**********************************************************
  22.  *      ULONG getsystime(struct timeval *tv)
  23.  *
  24.  * This is the old function and is used when ZEDZAP is DEFINED
  25.  **********************************************************
  26.  *
  27.  * Returns current system time in standard Amiga-style timeval
  28.  * structure, if you pass a pointer to one.  Also returns the
  29.  * seconds part as the return value.  This lets you get just
  30.  * the seconds by calling getsystime(NULL) if that's all you
  31.  * want, or the full timeval struct if you need that.  This
  32.  * is very similar to how the standard time() function is used.
  33.  *
  34.  **********************************************************/
  35.  ULONG
  36. getsystime(struct timeval *tv)
  37.  {
  38.  struct timerequest tr;
  39.  
  40.  /*
  41.  * timer.device must be working or the system would've died, so let's
  42.  * not bother with error checking.
  43.  */
  44.  
  45.  memset(&tr, 0, sizeof(tr));
  46.  OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest *) &tr, 0L);
  47.  
  48.  tr.tr_node.io_Message.mn_Node.ln_Type = NT_MESSAGE;
  49.  tr.tr_node.io_Command = TR_GETSYSTIME;
  50.  
  51.  DoIO((struct IORequest *) &tr);
  52.  
  53.  if (tv)
  54.  *tv = tr.tr_time;
  55.  
  56.  CloseDevice((struct IORequest *) &tr);
  57.  
  58.  return tr.tr_time.tv_secs;
  59.  }      /* End of ULONG getsystime() */
  60.  
  61. #else 
  62. /**********************************************************
  63.  *      ULONG getsystime(struct timeval *tv)
  64.  *
  65.  *      This function was rewritten using DateStamp() to
  66.  * eliminate the opening and closing of the timer.device
  67.  * that was occurring everytime this function was called.
  68.  * An attempt to save some processing time.   -WMP-
  69.  **********************************************************/
  70. ULONG 
  71. getsystime (struct timeval *tv)
  72. {
  73.   struct DateStamp ds;
  74.   ULONG secs;
  75.  
  76.   DateStamp (&ds);
  77.  
  78.   secs = (ds.ds_Days * 86400) + (ds.ds_Minute * 60) + (ds.ds_Tick / TICKS_PER_SECOND);
  79.   if (tv)
  80.   {
  81.     tv->tv_secs = secs;
  82.     tv->tv_micro = 0;
  83.   }
  84.  
  85.   return secs;
  86. }
  87. #endif
  88.  
  89. /* End of getsystime.c source */
  90.